package com.todod.base.module.infra.controller.admin.basegenerateno;

import com.todod.base.module.infra.framework.redis.CacheService;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import com.todod.base.framework.common.pojo.CommonResult;
import static com.todod.base.framework.common.pojo.CommonResult.success;
import com.todod.base.module.infra.service.basegenerateno.BaseGenerateNoService;

@Tag(name = "管理后台 - 系统生成编号")
@RestController
@RequestMapping("/infra/base-generate-no")
@Validated
public class BaseGenerateNoController {
    @Resource
    private CacheService redisService;

    @Resource
    private BaseGenerateNoService baseGenerateNoService;

    @GetMapping("/getBaseGenerateNo")
    @Operation(summary = "获得系统生成编号")
    @Parameter(name = "name", description = "名称", required = true, example = "NH")
    public CommonResult<String> getBaseGenerateNo(@RequestParam("name") String seqName) {
        String baseGenerateNo = baseGenerateNoService.getSeqByTableAndNum(seqName, 8);
        return success(baseGenerateNo);
    }

    @GetMapping("/getGenerateNo")
    @Operation(summary = "获得系统生成编号")
    @Parameter(name = "name", description = "名称", required = true, example = "NH")
    public CommonResult<Long> getGenerateNo(@RequestParam("name") String rediskey) {
        Long incrementNum = redisService.getIncrementNum(rediskey);
        System.out.println("系统生成编号==>"+incrementNum);
        return success(incrementNum);
    }




}